import Vue from 'vue'

function hasRule(value) {
    let userRules = localStorage.getItem('btnRules')
    if (userRules == undefined || userRules == null) {
        return false;
    }

    let arr = userRules.split(",");
    return arr.includes(value);
}

// 权限指令
// let has = 
Vue.directive('has', {
    // 当绑定的元素插入到DOM时
    inserted(el, binding) {
        let rule = binding.value
        if (!hasRule(rule)) {
            if (!el.parentNode) {
                el.parentNode.removeChild(el);
            } else {
                Vue.nextTick(() => {
                    el.parentNode.removeChild(el)
                });
            }
        }
    }
})

export { hasRule }